package com.kevin.spider.zookeeper.service;

import org.apache.curator.framework.CuratorFramework;
import org.springframework.stereotype.Service;

/**
 * @author kevin
 */
@Service
public class ZooKeeperService {
    private final CuratorFramework client;

    public ZooKeeperService(CuratorFramework client) {
        this.client = client;
        this.client.start(); // 启动客户端连接
    }

    public void createNode(String path, byte[] data) throws Exception {
        client.create().creatingParentsIfNeeded().forPath(path, data);
    }

    public void deleteNode(String path) throws Exception {
        client.delete().forPath(path);
    }

    public byte[] getData(String path) throws Exception {
        return client.getData().forPath(path);
    }
}
